// 两数相加

function ListNode(val, next) {
  this.val = (val === undefined ? 0 : val)
  this.next = (next === undefined ? null : next)
}

let addTwoNumbers = function (l1, l2) {
  let a = 0;
  let b = 0;
  let n1 = 0;
  let n2 = 0;
  for (let i = l1.length - 1; i > -1; i--) {
    a += l1[i] * Math.pow(10, n1);
    n1 = n1 + 1;
  }
  for (let i = l2.length - 1; i > -1; i--) {
    b += l2[i] * Math.pow(10, n2);
    n2 = n2 + 1;
  }
  let c = a + b;
  return c.toString().split("").map(ls => parseInt(ls)).reverse();
};

console.log(addTwoNumbers([9, 9, 9, 9, 9, 9, 9], [9, 9, 9, 9]));